<template>
  <div class="xiecheng">
    <div class="admin_main_block">
      <div class="admin_main_block_top">
        <div class="admin_main_block_left">
          <div>{{ i18n('business.container.schedule.view') }}</div>
        </div>

        <div class="admin_main_block_right">
          <div>
            <el-button icon="Back" @click="router.go(-1)">
              {{ i18n('common.return') }}
            </el-button>
          </div>
        </div>
      </div>

      <div class="admin_form_main">
        <el-form ref="formRef" :model="dataForm" label-width="80">
          <el-card class="box-card mt10" shadow="never" v-if="dataForm.shipowner">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.container.schedule.shipowner_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-row>
                <el-col :span="4">
                  <el-image class="cx-view-preview" :src="dataForm.shipowner.logo">
                    <template v-slot:error>
                      <div class="image-slot">
                        <el-icon><Picture /></el-icon>
                      </div>
                    </template>
                  </el-image>
                </el-col>
                <el-col :span="20">
                  <el-descriptions border>
                    <!-- 第1行 -->
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.chinese_name')" label-align="right">
                      {{ dataForm.shipowner.chinese_name }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.english_name')" label-align="right" :span="2">
                      {{ dataForm.shipowner.english_name }}
                    </el-descriptions-item>

                    <!-- 第2行 -->
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.chinese_short_name')" label-align="right">
                      {{ dataForm.shipowner.chinese_short_name }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.english_short_name')" label-align="right" :span="2">
                      {{ dataForm.shipowner.english_short_name }}
                    </el-descriptions-item>

                    <!-- 第3行 -->
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.mobile')" label-align="right">
                      {{ dataForm.shipowner.mobile }}
                    </el-descriptions-item>
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.email')" label-align="right" :span="2">
                      {{ dataForm.shipowner.email }}
                    </el-descriptions-item>

                    <!-- 第4行 -->
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.address')" label-align="right" :span="3">
                      {{ dataForm.shipowner.address }}
                    </el-descriptions-item>

                    <!-- 第5行 -->
                    <el-descriptions-item width="200" :label="i18n('business.shipowner.description')" label-align="right" :span="3">
                      {{ dataForm.shipowner.description }}
                    </el-descriptions-item>
                  </el-descriptions>
                </el-col>
              </el-row>
            </div>
          </el-card>

          <el-card class="box-card mt10" shadow="never">
            <template v-slot:header>
              <div class="clearfix">
                <span>{{ i18n('business.container.schedule.schedule_info') }}</span>
              </div>
            </template>
            <div class="text item">
              <el-descriptions border>
                <!-- 第1行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.polCode')" label-align="right">
                  {{ dataForm.polCode }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.polCountry')" label-align="right">
                  <el-text v-if="dataForm.start">{{ dataForm.start.nation_english_name }}</el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.polName')" label-align="right">
                  <el-text v-if="dataForm.start">{{ dataForm.start.english_name }}</el-text>
                </el-descriptions-item>

                <!-- 第2行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.podCode')" label-align="right">
                  {{ dataForm.podCode }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.podCountry')" label-align="right">
                  <el-text v-if="dataForm.end">{{ dataForm.end.nation_english_name }}</el-text>
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.podName')" label-align="right">
                  <el-text v-if="dataForm.end">{{ dataForm.end.english_name }}</el-text>
                </el-descriptions-item>

                <!-- 第3行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.cyCutoff')" label-align="right">
                  {{ dataForm.cyCutoff }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.routeCode')" label-align="right">
                  {{ dataForm.routeCode }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.isTransit')" label-align="right">
                  {{ dataForm.isTransit }}
                </el-descriptions-item>

                <!-- 第3行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.routeEta')" label-align="right">
                  {{ dataForm.routeEta }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.routeEtd')" label-align="right" :span="2">
                  {{ dataForm.routeEtd }}
                </el-descriptions-item>

                <!-- 第4行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.staticEta')" label-align="right">
                  {{ dataForm.staticEta }}
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.staticEtd')" label-align="right" :span="2">
                  {{ dataForm.staticEtd }}
                </el-descriptions-item>

                <!-- 第5行 -->
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.totalDuration')" label-align="right">
                  {{ dataForm.totalDuration }}天
                </el-descriptions-item>
                <el-descriptions-item width="200" :label="i18n('business.container.schedule.etd')" label-align="right" :span="2">
                  {{ dataForm.etd }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-card>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script setup name="business-container-schedule-view">
  import { useBase } from "@/hooks/base/useBase"
  import { useForm } from "@/hooks/form/useForm"

  const { router, query, i18n, isAuth } = useBase()

  const model = ref('business/container/schedule')

  const dataForm = reactive({
    id: 0,
    isTransit: '',
    scac: '',
    routeCode: '',
    polCode: '',
    podCode: '',
    routeEtd: '',
    staticEtd: '',
    etd: '',
    routeEta: '',
    staticEta: '',
    totalDuration: '',
    cyCutoff: '',
    transit_status: '',
    shipowner: [],
    start: [],
    end: []
  })

  const dataRule = reactive({})

  const {
    formRef
  } = useForm(model.value, dataForm)

  const init = (form) => {
    dataForm.id = query.id || 0

    nextTick(() => {
      form.value.resetFields()
      if (dataForm.id) {
        $http({
          url: $http.adornUrl(`/${model.value}/view/${dataForm.id}`),
          method: 'get',
          params: $http.adornParams({}),
        }).then(({ data }) => {
          if (data && data.status === 200) {
            dataForm.id = data.data.id
            dataForm.isTransit = data.data.is_transit_text.text
            dataForm.transit_status = data.data.is_transit_text.value == 1 ? true : false
            dataForm.scac = data.data.scac
            dataForm.routeCode = data.data.routeCode
            dataForm.polCode = data.data.polCode
            dataForm.podCode = data.data.podCode
            dataForm.routeEtd = data.data.routeEtd
            dataForm.staticEtd = data.data.staticEtd
            dataForm.etd = data.data.etd
            dataForm.routeEta = data.data.routeEta
            dataForm.staticEta = data.data.staticEta
            dataForm.totalDuration = data.data.totalDuration
            dataForm.cyCutoff = data.data.cyCutoff
            dataForm.shipowner = data.data.shipowner
            dataForm.start = data.data.start
            dataForm.end = data.data.end
          }
        })
      }
    })
  }

  onMounted(() => {
    init(formRef)
  })
</script>
